package mlz.i_stringJoiner;

import java.util.SplittableRandom;
import java.util.StringJoiner;

//案例: 将数组转换成字符串
public class WorkDemo {
    public static void main(String[] args) {
        String data = getArrayData(new int[]{1, 2, 3, 4, 5});
        System.out.println(data);//[1,2,3,4,5]
    }

    //案例: 将数组转换成字符串s
    public static String getArrayData(int[] arr){
        //1.判断数组是否为null
        if (arr == null){
            return null;
        }
        //2.如果数组不为null,在进行遍历操作,并且拼接数组中的元素
        StringJoiner s = new StringJoiner(",", "[", "]");
        for (int i = 0; i < arr.length; i++) {
            s.add(String.valueOf(arr[i]));
        }
        return s.toString();
    }
}






